package com.lemeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lemeng.entity.PageResult;
import com.lemeng.entity.Result;
import com.lemeng.pojo.Brand;
import com.lemeng.service.BrandService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("brand")
public class BrandController {

    public static void main(String[] args) {
        Brand brand = new Brand();
        brand.setName("666");
        brand.setId(1);
        str(brand.getName(),brand);
        System.out.println(brand.getName());//666
        System.out.println(brand.getId());//2


    }

    public static void str(String str,Brand brand){
        str = "777";
        brand.setId(2);
    }



    @Reference
    BrandService brandService;


    @GetMapping("findAll")
    public List<Brand> findAll(){
        return brandService.findAll();
    }

    @GetMapping("findPage")
    public PageResult<Brand> findPage(Integer page, Integer size) {
        return brandService.findPage(page,size);
    }

    @PostMapping("findList")
    public List<Brand> findList(@RequestBody Map<String, Object> serchMap) {
        return brandService.findList(serchMap);
    }
    @PostMapping("findPage")
    public PageResult<Brand> findPage(Integer page, Integer size,@RequestBody Map<String, Object> serchMap) {
        return brandService.findPage(page,size,serchMap);
    }
    @GetMapping("findById")
    public Brand findById(@RequestParam Integer id) {
        return brandService.findById(id);
    }

    @PostMapping("add")
    public Result add(@RequestBody Brand brand) {
        brandService.add(brand);
        return new Result();
    }
    @PostMapping("update")
    public Result update(@RequestBody Brand brand) {
        brandService.update(brand);
        return new Result();
    }

    @GetMapping("delete")
    public Result delete(Integer id) {
        brandService.delete(id);
        return new Result();
    }
    @GetMapping("deleteAll")
    public Result delete(String ids) {

        String[] split = ids.split(",");
        for (String id : split) {
            brandService.delete(Integer.parseInt(id));
        }


        return new Result();
    }


}
